package com.golf.core.course.bodies;

import java.util.ArrayList;
import java.util.List;

import net.phys2d.math.ROVector2f;
import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;
import net.phys2d.raw.StaticBody;
import net.phys2d.raw.shapes.Polygon;


public class PolyWall extends AbstractCourseBody
{
	
	private final List<Position> vertices = new ArrayList<Position>();
	
	
	public PolyWall(final String name) 
	{
		super(name);
	}
	
	
	public void addVertex(Position pos)
	{
		vertices.add(pos);
	}

	
	public List<Position> getVertices()
	{
		// make therad safe
		return vertices;
	}
	
	public Body asPhysicsBody() 
	{
		ROVector2f[] av = new Vector2f[vertices.size()];
		int count = 0;
		for (Position p : vertices)
		{
			av[count] = new Vector2f(p.getX(), p.getY());
			count++;
		}
		
        Body body = new StaticBody(name(), new Polygon(av));
        body.setPosition(0, 0);

        body.setRestitution(0.4f);
        body.setFriction(1.5f);
        
        return body;
	}

}
